<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>定时任务日志</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<div style="margin-top: 10px;">
    <table id="sysJoblogTable" lay-filter="sysJoblogTable"></table>
</div>
<!-- 列表头部工具栏 -->
<script type="text/html" id="sysJoblogHeaderToolsBar">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="delete">
            <i class="layui-icon layui-icon-delete"></i>
            <span>删除</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="clears">
            <i class="layui-icon layui-icon-refresh"></i>
            <span>重置</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="back">
            <i class="layui-icon layui-icon-return"></i>
            <span>返回</span>
        </a>
    </div>
    <form class="layui-form" action="" lay-filter="sysJoblogQueryForm" style="margin-right: 30px;">
        <div class="layui-row" style="margin-top: 10px;">
            <div class="selch table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label">任务名称</label>
                    <input type="text" class="layui-input filter-value" name="Q_jobName_SL" placeholder="任务名称"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">计划名称</label>
                    <input type="text" class="layui-input filter-value" name="Q_trigName_SL" placeholder="计划名称"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">开始时间</label>
                    <input type="text" class="layui-input start_time filter-value" name="Q_beginStartTime_DL" placeholder="开始时间"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">结束时间</label>
                    <input type="text" class="layui-input end_time filter-value" name="Q_endEndTime_DG" placeholder="结束时间"/>
                </div>
            </div>
        </div>
    </form>

</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="sysJoblogRightToolsBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'setter', 'form', 'common','totalFilter','commons','jquery'], function () {
        var table = layui.table;
        var setter = layui.setter;
        var form = layui.form;
        var common = layui.common;
        var commons = layui.commons;
        var $ = layui.jquery;
        var totalFilter = layui.totalFilter;
        common.tableSort('sysJoblogTable');

        var tableH=commons.tabHeight('full-70');

        var jobName = "${jobName}";

        //第一个实例
        table.render({
            elem: '#sysJoblogTable'
            ,height:tableH
            ,url: serverPath.systemPath + setter.sysLinkPath + 'sysJobLog/list?jobName='+jobName
            ,page: true //开启分页
            ,defaultToolbar: ['filter', 'print']
            ,toolbar: '#sysJoblogHeaderToolsBar'
            ,method: 'post'
            ,autoSort: true //是否排序
            ,cols: [[ //表头
                {field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}
                ,{type: 'checkbox', fixed: 'left'}
                ,{field: 'logId', title: 'logId',hide:true,sort:true, sortname: 'logid'}
                ,{field: 'jobName', title: '任务名称',sort:true, sortname: 'jobname'}
                ,{field: 'trigName', title: '计划名称',sort:true, sortname: 'trigname'}
                //如需转换为:yyyy-MM-dd HH:mm:ss: return commons.timeData(d.startTime,"1");
                //如需转换为HH:mm:ss: return commons.timeData(d.startTime,"2");
                // 当前转换后的格式为yyyy-MM-dd: return commons.timeData(d.startTime);
                ,{field: 'startTime', title: '开始时间',sort:true, sortname: 'starttime',templet: function (d) {
                    return commons.timeData(d.startTime,"1");
                }}
                //如需转换为:yyyy-MM-dd HH:mm:ss: return commons.timeData(d.endTime,"1");
                //如需转换为HH:mm:ss: return commons.timeData(d.endTime,"2");
                // 当前转换后的格式为yyyy-MM-dd: return commons.timeData(d.endTime);
                ,{field: 'endTime', title: '结束时间',sort:true, sortname: 'endtime',templet: function (d) {
                    return commons.timeData(d.endTime,"1");
                }}
                ,{field: 'content', title: '结果',sort:true, sortname: 'content'}
                ,{field: 'state', title: '状态',sort:true, sortname: 'state'}
                ,{field: 'runTime', title: '执行时间(秒)',sort:true, sortname: 'runtime'}
                ,{
                    fixed: 'right',
                    align: 'center',
                    title: '管理',
                    toolbar: '#sysJoblogRightToolsBar'
                }
            ]]
        });

        totalFilter.init('sysJoblogTable');
        commons.reflashDate({startName:'.start_time',endName:'.end_time'});

        function reflashQuery(isClear) {
            common.tableConditionRender("sysJoblogTable","sysJoblogQueryForm",{where:{}},isClear);
        }

        var baseUrl = "${baseUrl}";
        table.on('toolbar(sysJoblogTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
            switch (obj.event) {
                case 'delete':
                    var array = "";
                    for (var i = 0; i < data.length; i++) {
                        array+=data[i].logId+",";
                    }
                    delFun(data,array);
                    break;
                case "query":
                    reflashQuery(false);
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    break;
                case "clears":
                    reflashQuery(true);
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    break;
                case "back":
                    $(this).attr("href", baseUrl);
                    location.href = "#" +baseUrl;
                    break;
            };
        });

        table.on('tool(sysJoblogTable)', function(obj) {
            var data = obj.data, //获得当前行数据
                layEvent = obj.event; //获得 lay-event 对应的值
            switch(layEvent){
                case "del":
                    delFun(data,data.logId);
                    break;
            }
        });

        function delFun(data,id) {
            if (data.length === 0) {
                layer.msg('请先选择一行数据!');
            } else {
                layer.confirm('确定删除当前数据吗?', function (index) {
                    layer.close(index);
                    $.ajax({
                        url: serverPath.systemPath + setter.sysLinkPath + "sysJobLog/del",
                        type: "post",
                        data: {id:id},
                        dataType: 'json',
                        success: function (data) {
                            layer.alert(data.msg);
                            //执行重载
                            reflashQuery(true);
                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(data.msg);
                            //执行重载
                            reflashQuery(true);
                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        }
                    })
                })
            }
        }

        window.Initialization = function () {
            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
        };
        /*刷新时间控件*/
        commons.reflashDate({startName:'.start_time',endName:'.end_time'});
        common.tableSort("sysJoblogTable",{show:window.Initialization});
    });
</script>
</body>
</html>